import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

// 28684
public class P61 {
	private static List<Num> p(int type) {
		List<Num> list = new ArrayList<Num>();
		
		for (int n = 1; true; n++) {
			int x = 0;
			
			if (type == 3) {
				x = n * (n + 1) / 2;
			} else if (type == 4) {
				x = n * n;
			} else if (type == 5) {
				x = n * (3 * n - 1) / 2;
			} else if (type == 6) {
				x = n * (2 * n - 1);
			} else if (type == 7) {
				x = n * (5 * n - 3) / 2;
			} else if (type == 8) {
				x = n * (3 * n - 2);
			}
			
			//System.out.println(x);
						
			String value = String.valueOf(x);
			int length = value.length();
						
			Num num = new P61.Num();
			num.n = x;
			num.t = type;
			
			if (length == 4) {
				list.add(num);
			}
			
			if (length == 5) {
				return list;
			}
		}
	}
	
	static class Num {
		public int n;
		public int t;
	}
	
	static List<List<Num>> lists = new ArrayList<List<Num>>();
	
	// two digit map
	static Map<String, List<Num>> twoDigitMap = new HashMap<String, List<Num>>();
	static Set<Num> numSet = new HashSet<Num>();
	static int s = 0;
	static List<Set<Num>> answerList = new ArrayList<Set<Num>>();
	
	public static void main(String[] args) {
		
		for (int i = 3; i <= 8; i++) {
			lists.add(p(i));
		}
		
		int sum = 0;
		for (int i = 0; i < lists.size(); i++) {
			List<Num> list = lists.get(i);
			sum += list.size();			
			
			for (Num num : list) {
				String value = String.valueOf(num.n);
				String key = value.substring(0, 2);
				
				List<Num> l = twoDigitMap.get(key);
				if (l == null) {
					l = new ArrayList<Num>();
					twoDigitMap.put(key, l);
				}
				l.add(num);
				
				numSet.add(num);
			}
		}
		
		System.out.println(sum);
		System.out.println(numSet.size());
		
		ArrayList<P61.Num> cycleList = new ArrayList<P61.Num>();
		search(null, cycleList);
		
		for(Set<Num> set : answerList) {
			int s = 0;
			P61.Num[] n = set.toArray(new P61.Num[0]);
			for (int i = 0; i < n.length; i++) {
				Num num = n[i];
				s += num.n;
				System.out.print(num.n + ",");
			}
			System.out.println(s);
			
		}
	}
	
	static void search(Num num, List<Num> cycleList) {
		
		//System.out.println("list size:" + cycleList.size());
		
		try {
			//Thread.sleep(1000);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		if (num != null) {
			//System.out.println(num.n);
			
			for (Num n : cycleList) {
				if (n.t == num.t) {
					return;
				}
			}
			
			if (cycleList.size() == 5) {
				String value = String.valueOf(num.n);
				String key = value.substring(2, 4);
				if (String.valueOf(cycleList.get(0).n).startsWith(key)) {
					cycleList.add(num);		
				} else {
					return;
				}
			} else {
				cycleList.add(num);
			}
			
			
//			if (num.t == cycleList.size() + 3) {
//				System.out.println(num.n + "," + cycleList.size());
//				if (cycleList.size() == 2) {
//					String value = String.valueOf(num.n);
//					String key = value.substring(2, 4);
//					if (String.valueOf(cycleList.get(0).n).startsWith(key)) {
//						cycleList.add(num);		
//					} else {
//						return;
//					}
//				} else {
//					cycleList.add(num);
//				}
//			} else {
//				return;
//			}
			
		}
		
		if (cycleList.size() == 6) {
			
			
			boolean isNew = true;
			for (Set<Num> s : answerList) {
				if (s.containsAll(cycleList)) {
					isNew = false;
				}
			}
			
			if (isNew) {
				answerList.add(new LinkedHashSet<Num>(cycleList));
			}
			
			
						
			return;			
		}
		
		
		if (num != null) {
			String value = String.valueOf(num.n);
			String key = value.substring(2, 4);
			List<Num> list = twoDigitMap.get(key);
			if (list != null) {
				for (Num n : list) {
					search(n, new ArrayList<P61.Num>(cycleList));
				}
			}
		} else {
			Iterator<Num> iterator = numSet.iterator();
			while (iterator.hasNext()) {
				search(iterator.next(), new ArrayList<P61.Num>());			
			}	
		}
	}
}
